home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cuj9205.zip / 1005074A < prev    next >
Text File  |  1992-06-02  |  419b  |  26 lines

  1. /*
  2.  *    Listing 1 -- Error by reading a freed pointer
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <assert.h>
  7.  
  8. void    main() {
  9. int    *ip;
  10. int    n;
  11.  
  12.     /* allocate an integer */
  13.     ip = malloc(sizeof(int));
  14.     assert(ip != NULL);
  15.  
  16.     /* initialize the integer */
  17.     (*ip) = 1;
  18.  
  19.     /* deallocate the integer */
  20.     free(ip);
  21.  
  22.     /* use the deallocated integer */
  23.     n = 3 * (*ip);
  24.     printf("n may or may not equal 3 (n == %d)\n",n);
  25. }
  26.